// Licensed to Elasticsearch B.V under one or more agreements.
// Elasticsearch B.V licenses this file to you under the Apache 2.0 License.
// See the LICENSE file in the project root for more information.
//
// ███╗   ██╗ ██████╗ ████████╗██╗ ██████╗███████╗
// ████╗  ██║██╔═══██╗╚══██╔══╝██║██╔════╝██╔════╝
// ██╔██╗ ██║██║   ██║   ██║   ██║██║     █████╗
// ██║╚██╗██║██║   ██║   ██║   ██║██║     ██╔══╝
// ██║ ╚████║╚██████╔╝   ██║   ██║╚██████╗███████╗
// ╚═╝  ╚═══╝ ╚═════╝    ╚═╝   ╚═╝ ╚═════╝╚══════╝
// ------------------------------------------------
//
// This file is automatically generated.
// Please do not edit these files manually.
//
// ------------------------------------------------

#nullable restore

using Elastic.Clients.Elasticsearch.Serverless.Fluent;
using Elastic.Clients.Elasticsearch.Serverless.Serialization;
using System;
using System.Collections.Generic;
using System.Linq.Expressions;
using System.Text.Json;
using System.Text.Json.Serialization;

namespace Elastic.Clients.Elasticsearch.Serverless.Core.Search;

public sealed partial class RescoreQuery
{
	/// <summary>
	/// <para>The query to use for rescoring.<br/>This query is only run on the Top-K results returned by the `query` and `post_filter` phases.</para>
	/// </summary>
	[JsonInclude, JsonPropertyName("rescore_query")]
	public Elastic.Clients.Elasticsearch.Serverless.QueryDsl.Query Query { get; set; }

	/// <summary>
	/// <para>Relative importance of the original query versus the rescore query.</para>
	/// </summary>
	[JsonInclude, JsonPropertyName("query_weight")]
	public double? QueryWeight { get; set; }

	/// <summary>
	/// <para>Relative importance of the rescore query versus the original query.</para>
	/// </summary>
	[JsonInclude, JsonPropertyName("rescore_query_weight")]
	public double? RescoreQueryWeight { get; set; }

	/// <summary>
	/// <para>Determines how scores are combined.</para>
	/// </summary>
	[JsonInclude, JsonPropertyName("score_mode")]
	public Elastic.Clients.Elasticsearch.Serverless.Core.Search.ScoreMode? ScoreMode { get; set; }

	public static implicit operator Elastic.Clients.Elasticsearch.Serverless.Core.Search.Rescore(RescoreQuery rescoreQuery) => Elastic.Clients.Elasticsearch.Serverless.Core.Search.Rescore.Query(rescoreQuery);
}

public sealed partial class RescoreQueryDescriptor<TDocument> : SerializableDescriptor<RescoreQueryDescriptor<TDocument>>
{
	internal RescoreQueryDescriptor(Action<RescoreQueryDescriptor<TDocument>> configure) => configure.Invoke(this);

	public RescoreQueryDescriptor() : base()
	{
	}

	private Elastic.Clients.Elasticsearch.Serverless.QueryDsl.Query QueryValue { get; set; }
	private Elastic.Clients.Elasticsearch.Serverless.QueryDsl.QueryDescriptor<TDocument> QueryDescriptor { get; set; }
	private Action<Elastic.Clients.Elasticsearch.Serverless.QueryDsl.QueryDescriptor<TDocument>> QueryDescriptorAction { get; set; }
	private double? QueryWeightValue { get; set; }
	private double? RescoreQueryWeightValue { get; set; }
	private Elastic.Clients.Elasticsearch.Serverless.Core.Search.ScoreMode? ScoreModeValue { get; set; }

	/// <summary>
	/// <para>The query to use for rescoring.<br/>This query is only run on the Top-K results returned by the `query` and `post_filter` phases.</para>
	/// </summary>
	public RescoreQueryDescriptor<TDocument> Query(Elastic.Clients.Elasticsearch.Serverless.QueryDsl.Query query)
	{
		QueryDescriptor = null;
		QueryDescriptorAction = null;
		QueryValue = query;
		return Self;
	}

	public RescoreQueryDescriptor<TDocument> Query(Elastic.Clients.Elasticsearch.Serverless.QueryDsl.QueryDescriptor<TDocument> descriptor)
	{
		QueryValue = null;
		QueryDescriptorAction = null;
		QueryDescriptor = descriptor;
		return Self;
	}

	public RescoreQueryDescriptor<TDocument> Query(Action<Elastic.Clients.Elasticsearch.Serverless.QueryDsl.QueryDescriptor<TDocument>> configure)
	{
		QueryValue = null;
		QueryDescriptor = null;
		QueryDescriptorAction = configure;
		return Self;
	}

	/// <summary>
	/// <para>Relative importance of the original query versus the rescore query.</para>
	/// </summary>
	public RescoreQueryDescriptor<TDocument> QueryWeight(double? queryWeight)
	{
		QueryWeightValue = queryWeight;
		return Self;
	}

	/// <summary>
	/// <para>Relative importance of the rescore query versus the original query.</para>
	/// </summary>
	public RescoreQueryDescriptor<TDocument> RescoreQueryWeight(double? rescoreQueryWeight)
	{
		RescoreQueryWeightValue = rescoreQueryWeight;
		return Self;
	}

	/// <summary>
	/// <para>Determines how scores are combined.</para>
	/// </summary>
	public RescoreQueryDescriptor<TDocument> ScoreMode(Elastic.Clients.Elasticsearch.Serverless.Core.Search.ScoreMode? scoreMode)
	{
		ScoreModeValue = scoreMode;
		return Self;
	}

	protected override void Serialize(Utf8JsonWriter writer, JsonSerializerOptions options, IElasticsearchClientSettings settings)
	{
		writer.WriteStartObject();
		if (QueryDescriptor is not null)
		{
			writer.WritePropertyName("rescore_query");
			JsonSerializer.Serialize(writer, QueryDescriptor, options);
		}
		else if (QueryDescriptorAction is not null)
		{
			writer.WritePropertyName("rescore_query");
			JsonSerializer.Serialize(writer, new Elastic.Clients.Elasticsearch.Serverless.QueryDsl.QueryDescriptor<TDocument>(QueryDescriptorAction), options);
		}
		else
		{
			writer.WritePropertyName("rescore_query");
			JsonSerializer.Serialize(writer, QueryValue, options);
		}

		if (QueryWeightValue.HasValue)
		{
			writer.WritePropertyName("query_weight");
			writer.WriteNumberValue(QueryWeightValue.Value);
		}

		if (RescoreQueryWeightValue.HasValue)
		{
			writer.WritePropertyName("rescore_query_weight");
			writer.WriteNumberValue(RescoreQueryWeightValue.Value);
		}

		if (ScoreModeValue is not null)
		{
			writer.WritePropertyName("score_mode");
			JsonSerializer.Serialize(writer, ScoreModeValue, options);
		}

		writer.WriteEndObject();
	}
}

public sealed partial class RescoreQueryDescriptor : SerializableDescriptor<RescoreQueryDescriptor>
{
	internal RescoreQueryDescriptor(Action<RescoreQueryDescriptor> configure) => configure.Invoke(this);

	public RescoreQueryDescriptor() : base()
	{
	}

	private Elastic.Clients.Elasticsearch.Serverless.QueryDsl.Query QueryValue { get; set; }
	private Elastic.Clients.Elasticsearch.Serverless.QueryDsl.QueryDescriptor QueryDescriptor { get; set; }
	private Action<Elastic.Clients.Elasticsearch.Serverless.QueryDsl.QueryDescriptor> QueryDescriptorAction { get; set; }
	private double? QueryWeightValue { get; set; }
	private double? RescoreQueryWeightValue { get; set; }
	private Elastic.Clients.Elasticsearch.Serverless.Core.Search.ScoreMode? ScoreModeValue { get; set; }

	/// <summary>
	/// <para>The query to use for rescoring.<br/>This query is only run on the Top-K results returned by the `query` and `post_filter` phases.</para>
	/// </summary>
	public RescoreQueryDescriptor Query(Elastic.Clients.Elasticsearch.Serverless.QueryDsl.Query query)
	{
		QueryDescriptor = null;
		QueryDescriptorAction = null;
		QueryValue = query;
		return Self;
	}

	public RescoreQueryDescriptor Query(Elastic.Clients.Elasticsearch.Serverless.QueryDsl.QueryDescriptor descriptor)
	{
		QueryValue = null;
		QueryDescriptorAction = null;
		QueryDescriptor = descriptor;
		return Self;
	}

	public RescoreQueryDescriptor Query(Action<Elastic.Clients.Elasticsearch.Serverless.QueryDsl.QueryDescriptor> configure)
	{
		QueryValue = null;
		QueryDescriptor = null;
		QueryDescriptorAction = configure;
		return Self;
	}

	/// <summary>
	/// <para>Relative importance of the original query versus the rescore query.</para>
	/// </summary>
	public RescoreQueryDescriptor QueryWeight(double? queryWeight)
	{
		QueryWeightValue = queryWeight;
		return Self;
	}

	/// <summary>
	/// <para>Relative importance of the rescore query versus the original query.</para>
	/// </summary>
	public RescoreQueryDescriptor RescoreQueryWeight(double? rescoreQueryWeight)
	{
		RescoreQueryWeightValue = rescoreQueryWeight;
		return Self;
	}

	/// <summary>
	/// <para>Determines how scores are combined.</para>
	/// </summary>
	public RescoreQueryDescriptor ScoreMode(Elastic.Clients.Elasticsearch.Serverless.Core.Search.ScoreMode? scoreMode)
	{
		ScoreModeValue = scoreMode;
		return Self;
	}

	protected override void Serialize(Utf8JsonWriter writer, JsonSerializerOptions options, IElasticsearchClientSettings settings)
	{
		writer.WriteStartObject();
		if (QueryDescriptor is not null)
		{
			writer.WritePropertyName("rescore_query");
			JsonSerializer.Serialize(writer, QueryDescriptor, options);
		}
		else if (QueryDescriptorAction is not null)
		{
			writer.WritePropertyName("rescore_query");
			JsonSerializer.Serialize(writer, new Elastic.Clients.Elasticsearch.Serverless.QueryDsl.QueryDescriptor(QueryDescriptorAction), options);
		}
		else
		{
			writer.WritePropertyName("rescore_query");
			JsonSerializer.Serialize(writer, QueryValue, options);
		}

		if (QueryWeightValue.HasValue)
		{
			writer.WritePropertyName("query_weight");
			writer.WriteNumberValue(QueryWeightValue.Value);
		}

		if (RescoreQueryWeightValue.HasValue)
		{
			writer.WritePropertyName("rescore_query_weight");
			writer.WriteNumberValue(RescoreQueryWeightValue.Value);
		}

		if (ScoreModeValue is not null)
		{
			writer.WritePropertyName("score_mode");
			JsonSerializer.Serialize(writer, ScoreModeValue, options);
		}

		writer.WriteEndObject();
	}
}